package bsf.baseservice.businessmq.consumer;

import bsf.base.CallBack;
import bsf.baseservice.businessmq.systemruntime.MQMessage;
import bsf.baseservice.businessmq.systemruntime.log.DebugHelper;
import bsf.baseservice.businessmq.systemruntime.log.LogHelper;

/** 
 消费者监听器
 
*/
public class ReceiveMessageListener implements AutoCloseable
{
	private ConsumerHeartbeatProtect heartbeat = null;
	/** 
	 注册监听器
	 
	 @param action
	 @param context
	*/
	public void register(CallBack.Func1<Object,MQMessage> action, ConsumerContext context)
	{
		DebugHelper.writeLine(context.getMQPathID(), context.getMQPath(), "ReceiveMessageListener", "消费者开始监听器");
		context.Listener=this;
		context.ActionInfo.InnerAction=action;
		ReceiveMessageQuque quque = new ReceiveMessageQuque(context); //注册队列
		heartbeat = new ConsumerHeartbeatProtect(context); //注册心跳
		DebugHelper.writeLine(context.getMQPathID(), context.getMQPath(), "ReceiveMessageListener", "消费者监听器注册成功");
		LogHelper.writeLine(context.getMQPathID(), context.getMQPath(), "ReceiveMessageListener", "消费者监听器注册成功");
	}

	public final void close()
	{
		if (heartbeat != null)
		{
			heartbeat.close();
		}
	}
}